package com.example.huawei.system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.huawei.system.entity.ReserveMaintain;
import com.example.huawei.system.result.Result;
import com.example.huawei.system.service.ReserveMaintainService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Api(tags = "预约维保接口")
@RestController
@RequestMapping("/reserveMaintain")
public class ReserveMaintainController {

    @Autowired
    private ReserveMaintainService reserveMaintainService;

    @ApiOperation(value = "分页查询预约维保信息", notes = "分页查询预约维保信息")
    @GetMapping("/page")
    public Result<IPage<ReserveMaintain>> queryPage(@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
                                                    @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                    ReserveMaintain reserveMaintain) {
        Page<ReserveMaintain> page = new Page<>(pageNo, pageSize);
        return Result.ok(reserveMaintainService.queryPage(page,reserveMaintain));
    }

    @ApiOperation(value = "列表查询预约维保信息", notes = "列表查询预约维保信息")
    @GetMapping("/list")
    public Result<List<ReserveMaintain>> queryList(ReserveMaintain reserveMaintain) {
        return Result.ok(reserveMaintainService.queryList(reserveMaintain));
    }


    @ApiOperation(value = "新增预约维保信息", notes = "新增预约维保信息")
    @PostMapping("/add")
    public Result<?> add(@RequestBody ReserveMaintain reserveMaintain) {
        reserveMaintain.setCreateTime(new Date());
        boolean flag = reserveMaintainService.save(reserveMaintain);
        return flag ? Result.ok() : Result.error();
    }

    @ApiOperation(value = "修改预约维保信息", notes = "修改预约维保信息")
    @PutMapping("/edit")
    public Result<?> edit(@RequestBody ReserveMaintain reserveMaintain) {
        boolean flag = reserveMaintainService.updateById(reserveMaintain);
        return flag ? Result.ok() : Result.error();
    }

    @ApiOperation(value = "删除预约维保信息", notes = "删除预约维保信息")
    @DeleteMapping("/del/{id}")
    public Result<?> delete(@PathVariable("id") String id) {
        boolean flag = reserveMaintainService.removeById(id);
        return flag ? Result.ok() : Result.error();
    }
}
